package com.xblibo.xruth.security;
import javax.annotation.Resource;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.xblibo.xruth.service.UserService;
/**
 * <p>Title: SecurityManagerSupport.java </p>
 * <p>Description: 身份认证 </p>
 * <p>Copyright: 易宝 2011*版权所有 </p>
 * <p>Company: yeepay </p>
 * @author xblibo
 * @version 1.0 ,  2011  下午10:03:16
 */
@Service("userDetailsService")
public class SecurityManagerSupport implements UserDetailsService{
	
	@Resource(name="userService")
	private UserService userService;
	
	public UserDetails loadUserByUsername(String name)
			throws UsernameNotFoundException {
		 UserDetails user = userService.findUniqueBy("username", name);
		 if(user == null){
			 throw new UsernameNotFoundException("名称为"+name+"的用户不存在!");
		 }
		 return user;
	}
//	
//	//取得用户的权限
//	private Collection<GrantedAuthority> obtionGrantedAuthorities(User user) {
//		
//		return user.getAuthorities();
//	}

}
